package com.gitee.wsl.mathematics.algebraic

/**
 * Represents ring without multiplicative and additive identities i.e., algebraic structure with
 * associative, binary, commutative operation [add] and associative, operation [multiply] distributive over [add].
 *
 * @param T the type of element of this semiring.
 */
 interface RingOps<T> : GroupOps<T> {
    /**
     * Multiplies two elements.
     *
     * @param left the multiplier.
     * @param right the multiplicand.
     */
     fun multiply(left: T, right: T): T

    /**
     * Multiplies this element by scalar.
     *
     * @receiver the multiplier.
     * @param arg the multiplicand.
     */
     operator fun T.times(arg: T): T = multiply(this, arg)

    override fun binaryOperationFunction(operation: String): (left: T, right: T) -> T = when (operation) {
        TIMES_OPERATION -> ::multiply
        else -> super.binaryOperationFunction(operation)
    }

     companion object {
        /**
         * The identifier of multiplication.
         */
         const val TIMES_OPERATION: String = "*"
    }
}